package com.ruoyi.access.controller;

import com.ruoyi.access.domain.AccessControlRule;
import com.ruoyi.access.service.IAccessControlRuleService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/did/access")
public class AccessControlRuleController {

    @Resource
    private IAccessControlRuleService ruleService;

    // 查询全部规则
    @GetMapping("/list")
    public AjaxResult listRules() {
        List<AccessControlRule> rules = ruleService.listAllRules();
        return AjaxResult.success(rules);
    }

    // 查询单个规则
    @GetMapping("/{ruleId}")
    public AjaxResult getRule(@PathVariable Long ruleId) {
        return AjaxResult.success(ruleService.getRuleById(ruleId));
    }

    // 新增规则
    @PostMapping("/add")
    public AjaxResult addRule(@RequestBody AccessControlRule rule) {
        return AjaxResult.success("添加成功", ruleService.addRule(rule));
    }

    // 更新规则
    @PutMapping("/update")
    public AjaxResult updateRule(@RequestBody AccessControlRule rule) {
        return AjaxResult.success("更新成功", ruleService.updateRule(rule));
    }

    // 删除规则
    @DeleteMapping("/delete/{ruleId}")
    public AjaxResult deleteRule(@PathVariable Long ruleId) {
        return AjaxResult.success("删除成功", ruleService.deleteRule(ruleId));
    }
}
